package com.yy.try_;

/**
 * chapter12  com.yy.try_
 * 2023-05-10 09:27
 *
 * @author yy yuyue
 * description : 不可描述
 * @date 2023/5/10 9:27
 */
public class TryCatchExercise03 {
}
class ExceptionExe{

    public static int method(){
        int i = 1;//i = 1
        try {
            i++;//i = 2
            String[] names = new String[3];//String[] 数组
            if(names[1].equals("tom")){// NullPointerException  空指针
                System.out.println(names[1]);
            }else {
                names[3] = "yy";
            }
            return 1;
        }catch (ArrayIndexOutOfBoundsException e){
            return 2;
        }catch (NullPointerException e){//捕获
            return ++i;// i = 3 ==> 保存临时变量temp = 3;     i = i + 1;    tmp = i ;
            //return tmp;        tmp = ++i;
        }finally {//必须执行
             ++i;//i = 4
            System.out.println("i=" + i);// i = 4
        }
    }

    public static void main(String[] args) {
        System.out.println(method());//3
        // i = ++i;
        // i = i + 1;
          //tmp  = ++i;     i = i + 1;   k = i;     tmp = k;
        //i = i;
    }
}